package com.cloud.base.designmode.observer;

import java.util.ArrayList;
import java.util.List;


public class MsgSubject implements AbstractSubject {
    // 发送消息主题
    private List<ObServer> obServers = new ArrayList<>();

    @Override
    public void addObServer(ObServer obServer) {
        obServers.add(obServer);
    }

    @Override
    public void removeObServer(ObServer obServer) {
        obServers.remove(obServer);
    }

    @Override
    public void notifyObServerAll(String message) {
        // 循环遍历调用，每个ObServer
        obServers.forEach((o) -> {
            // 调用update
            o.update(message);
        });
    }
}
